package metalink.admin;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.sql.*;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import vo.*;
import vo.mixed.*;
import model.admin.*;
import myutil.*;


public class SaveQuery extends ActionSupport{
	private String query;
	private ArrayList<String> messages=new ArrayList<String>();
	public String execute(){
		try{
			HttpSession session = ServletActionContext.getRequest().getSession();
			String username = session.getAttribute("username").toString();
			Connect c=new Connect();
			ResultSet rs=c.getResult("select * from saved_queries where query like '"+query+"' and username='"+username+"'");
			if(rs.next()){
				messages.add("Query already saved");
			}
			else{
				c.dml("insert into saved_queries(username,query) values('"+username+"','"+query+"')");
				messages.add("Query saved successfully");
			}
			System.out.println(query);
			
		
			Thread.sleep(1000);
			return SUCCESS;
			
			
			
		}catch(Exception e){
			e.printStackTrace();
			return ERROR;
		}
	
		
	}
	public String getQuery() {
		return query;
	}
	public void setQuery(String query) {
		this.query = query;
	}
	public ArrayList<String> getMessages() {
		return messages;
	}
	public void setMessages(ArrayList<String> messages) {
		this.messages = messages;
	}

}
